# Contributor: kpcyrd <git@rxv.cc>
# Maintainer: kpcyrd <git@rxv.cc>
pkgname=acme-redirect
pkgver=0.7.0
pkgrel=0
pkgdesc="Tiny http daemon that answers acme challenges and redirects everything else to https"
url="https://github.com/kpcyrd/acme-redirect"
# ppc64le and s390x blocked by ring crate
# loongarch64 blocked by nix crates
arch="all !ppc64le !s390x !loongarch64"
license="GPL-3.0-or-later"
makedepends="
	cargo
	cargo-auditable
	openssl-dev>3
	scdoc
	"
subpackages="$pkgname-doc
	$pkgname-openrc
	$pkgname-bash-completion
	$pkgname-zsh-completion
	$pkgname-fish-completion
	"
install="$pkgname.pre-install"
options="net"
source="$pkgname-$pkgver.tar.gz::https://github.com/kpcyrd/acme-redirect/archive/v$pkgver.tar.gz"

build() {
	cargo auditable build --release --locked

	mkdir -p completions
	"target/release/acme-redirect" completions bash > completions/acme-redirect.bash
	"target/release/acme-redirect" completions zsh > completions/_acme-redirect
	"target/release/acme-redirect" completions fish > completions/acme-redirect.fish

	make docs
}

check() {
	cargo test --release --locked
}

package() {
	install -Dm755 "$builddir/target/release/acme-redirect" -t "$pkgdir/usr/bin"

	install -Dm755 "$builddir/contrib/openrc/$pkgname.initd" "$pkgdir/etc/init.d/$pkgname"
	install -Dm755 "$builddir/contrib/cron/acme-redirect.cron" \
		"$pkgdir"/etc/periodic/daily/acme-redirect

	install -Dm644 "$builddir/contrib/confs/acme-redirect.conf" -t "$pkgdir/etc"
	install -Dm644 "$builddir/contrib/confs/certs.d/example.com.conf" "$pkgdir/etc/acme-redirect.d/example.com.conf.sample"

	install -Dm644 -t "$pkgdir/usr/share/man/man1" \
		"$builddir/contrib/docs/acme-redirect.1"
	install -Dm644 -t "$pkgdir/usr/share/man/man5" \
		"$builddir/contrib/docs/acme-redirect.conf.5" \
		"$builddir/contrib/docs/acme-redirect.d.5"

	install -Dm644 "$builddir/completions/acme-redirect.bash" \
		"$pkgdir/usr/share/bash-completion/completions/acme-redirect"
	install -Dm644 "$builddir/completions/_acme-redirect" \
	    "$pkgdir/usr/share/zsh/site-functions/_acme-redirect"
	install -Dm644 "$builddir/completions/acme-redirect.fish" \
		"$pkgdir/usr/share/fish/vendor_completions.d/acme-redirect.fish"
}

sha512sums="
0be3aebb8fc46b3974e420f85df8bc7b2a4328bdbb2930a783b9f9d231ca99036455ff71b8b7ca11fb59e389815543fa5ce11f94795305a012ee39505d1d5e40  acme-redirect-0.7.0.tar.gz
"
